package com.word2pdf.springbootword2pdf.controller;

import com.aspose.words.Document;
import com.aspose.words.ParagraphFormat;
import com.aspose.words.SaveFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

/**
 * 应用模块名称
 *
 * @author Rex
 * @since 2024/4/12 11:34
 */
@RestController
@RequestMapping("/pangolin/test")
public class TestController {
    @GetMapping("/word2pdf")
    public String test() throws Exception {
        InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("word/response.docx");
        Document doc = new Document(inputStream);
        ParagraphFormat pf=doc.getStyles().getDefaultParagraphFormat();
        pf.clearFormatting();
        File tempPdfFile = new File("./temp.pdf");
        FileOutputStream os = new FileOutputStream(tempPdfFile);
        doc.save(os, SaveFormat.PDF);
        return "1";
    }

}
